from 区划查询 import getRegionCode


class Item:
    cookies = {
        'JSESSIONID': '767F3D3B9BF36BF596E8651B3A0AF5F1',
        'YJSESSIONID': 'E75FEFE723D642FBA7EF7384E269140D',
    }

    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0',
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
        # 'Accept-Encoding': 'gzip, deflate',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'X-Requested-With': 'XMLHttpRequest',
        'Origin': 'http://59.215.206.252:1606',
        'Connection': 'keep-alive',
        'Referer': 'http://59.215.206.252:1606/sxglfz/mng/folder/config/entry/index?v=1716258545798',
        # 'Cookie': 'JSESSIONID=03AA729A70A2D21F8CEAC5E119CE2A0E; YJSESSIONID=E75FEFE723D642FBA7EF7384E269140D',
        'Priority': 'u=1',
    }

    def query(self,regionCode='52030214'):
        import requests


        data = {
            '_search': 'true',
            'nd': '1716262078652',
            'rows': '50000',
            'page': '1',
            'sidx': 'ID',
            'sord': 'desc',
            'name': '',
            'type': '',
            'regionCode': '{}'.format(regionCode),
            'org_code': '',
            'status': '',
        }

        response = requests.post('http://59.215.206.252:1606/sxglfz/mng/folder/config/query', cookies=self.cookies,
                                 headers=self.headers, data=data).json()


        dates=[]
        for item in response['rows']:
            date = []
            # print(item['cell'])
            # print(item['cell']['ID'],)
            date.append(item['cell']['ID'])
            date.append(item['cell']['CODE'])
            date.append(item['cell']['AGENT_NAME'])
            date.append(item['cell']['NAME'])
            # print(item['cell']['ID'])
            # print(item['cell']['CODE'])
            # print(item['ID'])
            # print(item['CODE'])
            dates.append(date)
        return dates
    def delete(self,orgin):
        import requests
        num=self.query(orgin)
        for i in num:




            params = {
                'method': 'batchDeleteFolder',
            }
        # 事项ID  事项编码
            code = str(i[1]+';')
            ids = str(i[0]+';')
            部门 = str(i[2])
            目录 = str(i[3]+';')


            data ={"ids":"{}".format(ids),
                   "codes":"{}".format(code)}


            response = requests.post(
                'http://59.215.206.252:1606/sxglfz/mng/folder/config',
                params=params,
                cookies=self.cookies,
                headers=self.headers,
                json=data,
            ).json()


            import re



            match = re.findall("(?<=codes:).*?(?=;})", code)
            print(response['msg']+">"+code+"+"+部门+"-"+目录)

    def start(self):
        import concurrent.futures
        orgion_code=getRegionCode().getRegionCode()
        for code in orgion_code:
            if code !='52033010':
                continue
            with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
                # 提交两个任务到线程池
                executor.submit(self.delete(code))
            # self.delete(code)


Item().start()